{extend name="public:base"}
{block name='css'}
<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="__PUBLIC__/css/style.min862f.css" rel="stylesheet">
{/block}
{block name="js"}
<script src="__PUBLIC__/js/content.min.js?v=1.0.0"></script>
<script src="__PUBLIC__/js/plugins/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/plugins/validate/messages_zh.min.js"></script>

<script type="text/javascript">
    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        },
        success: function(e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    });

    $().ready(function() {
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#commentForm").validate({
            rules: {
                title: "required",
                sort: "required"
            },
            messages: {
                title: e + "请输入{:$what}名称",
                sort: e + "请输入排序"
            },
            submitHandler: function(form){
                if ($(form).hasClass('ed')) {
                    return false;
                }

                $(form).addClass('ed');
                var obj = showMyLoading();
                $.post('{:url("save", ["type"=>$type])}', $(form).serialize(), function(data){
                    hideMyLoading(obj);
                    layer.msg(data.info);
                    if (data.status == 'y') {
                        window.location.href = '{:url("index", ["type"=>$type, "id"=>$pid])}';
                    } else {
                        $(form).removeClass('ed');
                    }
                }, 'json');
            },
            invalidHandler: function(form, validator) {  //不通过回调
                return false;
            }
        })
    });
</script>
{/block}
{block name='body'}
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>添加{:$what}</h5>
                        <a href="javascript:history.go(-1);" class="btn btn-sm btn-primary pull-right m-t-n-xs">返回</a>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="commentForm" action="" enctype="multipart/form-data" >
							<input type="hidden" name="id" value="{$data.id}" />
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:$what}名称</label>
                                <div class="col-sm-10">
                                    <input type="text" name="title" value="{$data.title}" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">上级</label>
                                <div class="col-sm-10" style="line-height: 30px;">
                                    {switch name='type'}
                                        {case value='city'}{:session('region.province')['title']}{/case}
                                        {case value='area'}{:session('region.province')['title']} | {:session('region.city')['title']}{/case}
                                        {default /}无上级
                                    {/switch}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序</label>
                                <div class="col-sm-10">
                                    <input type="text" name="sort" value="{$data.sort}" class="form-control">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存内容</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>
{/block}
